package com.os.sys.repository;

import com.os.sys.model.T_SYS_User;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Administrator on 2017/6/14.
 */
public interface UserRepository extends PagingAndSortingRepository<T_SYS_User, Long>, JpaSpecificationExecutor<T_SYS_User> {
    @Query("select t from T_SYS_User t where (t.userAccount=:acc or t.userMobile=:acc or t.userEMail=:acc) and t.userPassword=:pwd and t.userEnable=1")
    T_SYS_User loginByAcc(@Param("acc") String accOrMobileOrEMail, @Param("pwd") String pwd);

    List<T_SYS_User> findAllByIdIn(List<Long> ids);

    @Modifying
    @Transactional
    void deleteByIdIn(List<Long> ids);

    T_SYS_User findByUserAccount(String acc);

    T_SYS_User findByUserMobile(String mobile);

    @Query("select t from T_SYS_User t where (t.userAccount=:acc or t.userMobile=:acc or t.userEMail=:acc) and t.userPassword=:pwd and t.userEnable=1")
    T_SYS_User login(@Param("acc") String acc, @Param("pwd") String pwd);

}
